package cn.lhn.ridersclub.controller;

import cn.lhn.ridersclub.dto.LoginResult;
import cn.lhn.ridersclub.dto.Result;
import cn.lhn.ridersclub.entity.Login;
import cn.lhn.ridersclub.service.LoginService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class LoginController {

    private final LoginService loginService;

    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }

    @PostMapping("/password")
    public Result<LoginResult> loginByPassword(String email, String password) {
        LoginResult loginResult = loginService.loginByPassword(email, password);
        return Result.success("登录成功", loginResult);
    }

    @PostMapping("/captcha")
    public Result<LoginResult> loginByCaptcha(String email, String code) {
        LoginResult loginResult = loginService.loginByCaptcha(email, code);
        return Result.success("登录成功", loginResult);
    }

    @PostMapping("/update")
    public Result<?> updatePassword(String email, String code, String password) {
        loginService.updatePassword(email, code, password);
        return Result.success().message("更新成功");
    }
}
